// $Id: socket.h 33 2011-04-14 18:49:15Z cedric.shih@gmail.com $
/*
 * Copyright (C) 2010 Cedric Shih <cedric.shih@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef NIOSOCKET_H_
#define NIOSOCKET_H_

#ifdef __cplusplus
extern "C" {
#endif

#ifndef WIN32
#define SOCKET int
#define INVALID_SOCKET -1
#endif

struct niosocket;

struct niosocket *niosocket_new(void);

void niosocket_free(struct niosocket *socket);

int niosocket_connect(struct niosocket *socket,
		struct in_addr *address, unsigned short port);

int niosocket_listen(struct niosocket *socket,
		struct in_addr *address, unsigned short port,
		unsigned int backlog);

int niosocket_bind(struct niosocket *socket,
		struct in_addr *address, unsigned short port);

int niosocket_accept(struct niosocket *socket,
		struct niosocket *channel);

int niosocket_attach(struct niosocket *socket, SOCKET descriptor);

int niosocket_set_address(struct niosocket *socket,
		struct in_addr *address, unsigned short port);

SOCKET niosocket_describe(struct niosocket *socket);

ssize_t niosocket_read(struct niosocket *socket, void *buf, size_t count);

ssize_t niosocket_write(struct niosocket *socket,
		const void *buffer, size_t count);

int niosocket_close(struct niosocket *socket);

#ifdef __cplusplus
}
#endif

#endif /* NIOSOCKET_H_ */
